<template>
  <div class="login-container" >
    <div class="login-form">
      <div class="welcome-message styled-welcome">欢迎登录</div>
      <el-form ref="form" :model="form" :rules="rules" size="normal">
        <el-form-item prop="username">
          <el-input :prefix-icon="User" v-model="form.username" placeholder="用户名" class="rounded-input" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input :prefix-icon="Hide" v-model="form.password" show-password placeholder="密码" class="rounded-input" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login" class="styled-button">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
//... (Your JavaScript code remains the same)

import {Search, User, Hide} from "@element-plus/icons-vue";
import request from "@/utils/request";


export default {
  name: "AdminLogin",
  computed: {
    Hide() {
      return Hide
    },
    User() {
      return User
    },
    Search() {
      return Search
    }
  },
  data(){
    return {
      //此处将form定义成一个对象
      form: {},
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],
      }
    }

  },
  methods:{
    login() {

      //提前进行表单验证，
      this.$refs['form'].validate((valid) => {
        if (valid) {
          const button = this.$refs.form.$el.querySelector('.styled-button');
          button.classList.add('button-pressed');
          request.post("/admin/login", this.form).then(res => {
            button.classList.remove('button-pressed');
            if (res.code === '0') {
              this.$message({
                type: "success",
                message: "登录成功"
              })
              sessionStorage.setItem("user", JSON.stringify(res.data))//缓存用户信息
              this.$router.push("/Admin");//登录成功之后进行页面跳转，跳转到主页
            } else {
              this.$message({
                type: "error",
                message: res.msg
              })
            }
          })
        }
      })

    }
  }
}


</script>

<style scoped>
.login-container {
  width: 100%;
  height: 100vh;
  background-color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.login-form {
  width: 400px;
  margin: 100px auto;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.login-form:hover {
  transform: scale(1.05);
}

.welcome-message {
  color: black;
  font-size: 30px;
  text-align: center;
  padding: 30px 0;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-button {
  width: 100%;
  font-weight: bold;
}

.rounded-input.el-input__inner {
  border-radius: 20px; /* 调整输入框的圆角大小 */
}

.styled-button {
  background-color: #4CAF50; /* 按钮背景颜色 */
  color: white; /* 按钮文字颜色 */
  border: none; /* 移除边框 */
  border-radius: 5px; /* 圆角 */
  padding: 10px 20px; /* 内边距 */
  text-align: center; /* 文字居中 */
  text-decoration: none; /* 取消文字下划线 */
  display: inline-block;
  font-size: 16px;
  transition-duration: 0.4s; /* 过渡效果持续时间 */
  cursor: pointer;
}

.styled-button:hover {
  background-color: brown; /* 鼠标悬停时的背景颜色 */
}

.styled-button.button-pressed {
  transform: scale(0.95);
}

.styled-welcome {
  font-size: 32px; /* 文字大小 */
  font-weight: bold; /* 文字粗细 */
  color: #333; /* 文字颜色 */
  text-align: center; /* 文字居中 */
  margin-bottom: 20px; /* 下边距 */
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); /* 文字阴影 */
  /* 其他样式属性，比如字体、行高等 */
  font-family: "SimHei", sans-serif;
}

</style>